package online.heycm.codegenerator.config.task;

import lombok.extern.slf4j.Slf4j;
import online.heycm.codegenerator.common.session.SessionStorage;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

/**
 * @author hey
 * @version 1.0
 * @date 2024/1/5 10:38
 */
@Slf4j
@Configuration
@EnableScheduling
public class ScheduleTask {

    public static final int DELAY = 2 * 60 * 1000;

    @Scheduled(initialDelay = DELAY, fixedDelay = DELAY)
    public void clearSession() {
        log.info("[定时器] 清除过期Session开始...");
        long l = System.currentTimeMillis();
        int size = SessionStorage.clearTask(l);
        long ms = System.currentTimeMillis() - l;
        log.info("[定时器] 清除过期Session完成, 清理数量: {}, 耗时: {}ms", size, ms);
    }


}
